public class main {

    static int[] in = {2, 4,11,15, 1, 9, 5, 7,3,6,12,10};

    public static void main(String[] args) {
        for (int i = 1; i < in.length; i++) {
            buildMaxHeap(i);
        }
        for(int i=1;i<in.length;i++){
            swap(0, in.length-i);
            if(in.length-i==2){
                break;
            }
            int j = in[0+1]>=in[0+2]?0+1:0+2;
            if(in[0]<=in[j]){
                swap(0,j);
            }
        }
        System.out.println("args");
    }

    private static void buildMaxHeap(int i){
        if(i==0){
            return;
        }
        if (in[i] > in[(i+1)/2-1]) {
            swap(i,(i+1)/2-1);
            buildMaxHeap((i+1)/2-1);
        }
    }

    private static void swap(int i, int j) {
        int tmp = in[i];
        in[i] = in[j];
        in[j] = tmp;
    }
}
